/**
 * Created by Administrator on 2019/8/30.
 */
//验证用户名：必填，必须是数字字母组成，长度在6-12字符
function check_telno(){
    var flag =false;
    var telnoElement = document.querySelector("input[name='telno']");//获得手机号元素控件<input />
    var telno = telnoElement.value;  //获得手机号的值
    var telno_tip= telnoElement.parentElement.previousElementSibling.firstElementChild;
    if(telno == null || telno ==""){
        telno_tip.innerText="手机号不能为空";
    }else if( !/^[0-9]{11}$/.test(telno)  ){
        telno_tip.innerText="手机号错误"
    } else{
        telno_tip.innerText="";
        flag = true;
    }
    return flag;
}


function check_code(){
    if(check_telno()) {
        var flag = false;
        var codeElement = document.querySelector("input[name='code']");//获得验证码元素控件<input />
        var code = codeElement.value;  //获得验证码的值
        var code_tip = codeElement.parentElement.previousElementSibling.previousElementSibling.firstElementChild;
        if (code == null || code == "") {
            code_tip.innerText = "验证码不能为空";
        } else if (!/^[0-9A-Za-z]{4}$/.test(code)) {
            code_tip.innerText = "验证码错误";
        } else {
            code_tip.innerText = "";
            flag = true;
        }

        return flag;
    }
}


function check_con(){
    var contElement = document.querySelector(".check-content");
    if(document.querySelector(".check-content").checked){
        return true;
    }else{
        var con = contElement.parentElement.previousElementSibling.previousElementSibling.previousElementSibling.previousElementSibling.previousElementSibling.previousElementSibling.previousElementSibling.firstElementChild;
        con.innerText="阅读并同意大众点评网政策协议";
        return false;
    }
}


function check_password(){
    if(check_code()) {
        var flag = false;
        var pwdElement = document.querySelector("input[name='pwd']");
        var pwd = pwdElement.value;
        var pwd_alert = pwdElement.parentElement.previousElementSibling.previousElementSibling.previousElementSibling.firstElementChild;
        if (pwd == null || pwd == "") {
            pwd_alert.innerText = "密码不能为空";
        } else if (!/^[0-9A-Za-z]{6,12}$/.test(pwd)) {
            pwd_alert.innerText = "密码必须是字母或下划线组成,长度在6-12字符";
        } else {
            pwd.innerText = "";
            flag = true;
        }
        if(flag){
            flag=check_con();
            if(flag) {
                open("../front_demo/first_page.html");
            }
        }
        return flag;
    }
}
